<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button v-if="$AUTH('gjwl:wlGoods:add')" type="primary" icon="el-icon-plus" @click="add"></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search"><!-- 日期时间范围 -->
          <el-date-picker v-model="search.createTime" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"></el-date-picker>
          <el-input v-model="search.wlGoodsId" placeholder="包裹ID" clearable></el-input>
          <el-input v-model="search.wlWaybillId" placeholder="运单ID" clearable></el-input>
          <el-input v-model="search.hyUserId" placeholder="用户ID" clearable></el-input>
		  <el-select v-model="search.wlWarehouseId" placeholder="仓库">
		  	<!-- <el-option :value="1" label="深圳仓"></el-option> -->
		  	<el-option v-for="(item, index) in wlWarehouseList" :key="index" :label="item.wname" :value="item.wlWarehouseId"></el-option>
		  </el-select>
          <el-input v-model="search.wlWarehouseFqId" placeholder="仓库分区ID" clearable></el-input>
          <el-input v-model="search.wlWaybillPsId" placeholder="派送单ID" clearable></el-input>
          <el-input v-model="search.wlPackingbagId" placeholder="包装袋ID" clearable></el-input>
          <el-input v-model="search.cmCode" placeholder="快递单号" clearable></el-input>
          <el-input v-model="search.goodCode" placeholder="条形码" clearable></el-input>
          <el-input v-model="search.goodName" placeholder="品名" clearable></el-input>
          <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="apiObj" row-key="wlGoodsId" @selection-change="selectionChange" stripe>
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="包裹ID" prop="wlGoodsId" width="100"></el-table-column>
        <el-table-column label="运单" prop="waybillNumber" width="100"></el-table-column>
        <el-table-column label="用户" prop="userName" width="100"></el-table-column>
        <el-table-column label="仓库ID" prop="wlWarehouseIdName" width="100"></el-table-column>
        <el-table-column label="仓库分区ID" prop="wlWarehouseFqId" width="100"></el-table-column>
        <el-table-column label="派送单ID" prop="wlWaybillPsId" width="100"></el-table-column>
        <el-table-column label="包装袋ID" prop="wlPackingbagId" width="100"></el-table-column>
        <el-table-column label="快递单号" prop="cmCode" width="100"></el-table-column>
        <el-table-column label="条形码" prop="goodCode" width="100"></el-table-column>
        <el-table-column label="品名" prop="goodName" width="100"></el-table-column>
        <el-table-column label="收货机号" prop="machine" width="100"></el-table-column>
        <el-table-column label="重量kg" prop="gkg" width="100"></el-table-column>
        <el-table-column label="长cm" prop="gm3Chang" width="100"></el-table-column>
        <el-table-column label="宽cm" prop="gm3Kuan" width="100"></el-table-column>
        <el-table-column label="高cm" prop="gm3Gao" width="100"></el-table-column>
        <el-table-column label="体积m³" prop="gm3" width="100"></el-table-column>
        <el-table-column label="材重" prop="gcz" width="100"></el-table-column>
        <el-table-column label="异常" width="100">
			<template #default="scope22">
				<span v-if="scope22.row.wstate==0">正常</span>
				<span v-if="scope22.row.wstate==1">无主</span>
				<span v-if="scope22.row.wstate==2">破损</span>
				<span v-if="scope22.row.wstate==3">违禁</span>
				<span v-if="scope22.row.wstate==4">遗失</span>
			</template>
		</el-table-column><!--- 0正常 1无主 2破损 3违禁 4遗失,参数编码YcState-->
        <el-table-column label="状态" width="100">
			<template #default="scope11">
				<span v-if="scope11.row.status==1">待入库</span>
				<span v-if="scope11.row.status==2">执行中</span>
				<span v-if="scope11.row.status==8">已签收</span>
			</template>
		</el-table-column><!-- 0待入库 1执行中 8已签收 -->
        <el-table-column label="创建时间" prop="createTime" width="100"></el-table-column>
<!--    <el-table-column label="创建时间" prop="createTime" width="100" :formatter="formatDate"></el-table-column>-->
        <el-table-column label="操作" fixed="right" align="right">
          <template #default="scope">
            <el-button v-if="$AUTH('gjwl:wlGoods:edit')" type="text" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-button v-if="$AUTH('gjwl:wlGoods:del')" type="text" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>

  <wlGoodsEdit-dialog v-if="dialog.wlGoodsEdit" ref="wlGoodsEditDialog" @success="handleSaveSuccess" @closed="dialog.wlGoodsEdit=false"></wlGoodsEdit-dialog>
</template>

<script>
  import wlGoodsEditDialog from './wlGoodsEdit';//1--导入
  export default {
    name: 'wlGoods',
    components: {
        wlGoodsEditDialog//2发布
    },
    data() {
      return {
        dialog: {
          wlGoodsEdit: false
        },
        apiObj: this.$API.gjwl.wlGoods.list,
        selection: [],
        search: {
          keyword: null,
          createTime: null
        },
		wlWarehouseList:[],
      }
    },
    methods: {
      //添加
      add(){
        this.dialog.wlGoodsEdit = true
        this.$nextTick(() => {
          this.$refs.wlGoodsEditDialog.open()
        })
      },
      //编辑
      table_edit(row){
        this.dialog.wlGoodsEdit = true
        this.$nextTick(() => {
          this.$refs.wlGoodsEditDialog.open('edit').setData(row)
        })
      },
      //删除
      async table_del(row){
        var confirm = await this.$confirm('确定删除选中的项吗？', '提示', {
          confirmButtonText: 'ok',
          type: 'warning'
        }).catch(() => {})
        if(confirm !== 'confirm'){
          return false;
        }
        var res = await this.$API.gjwl.wlGoods.delete.delete(row.wlGoodsId);
        if(res.code === 2000){
          this.$refs.table.refresh();
          this.$message.success("删除成功");
        }else{
          this.$alert(res.message, "提示", {type: 'error'});
        }
      },
      //表格选择后回调事件
      selectionChange(selection){
        this.selection = selection;
      },
      //搜索
      upsearch(){
        this.$refs.table.upData(this.search);
      },
      //本地更新数据
      handleSaveSuccess(){
        this.$refs.table.refresh();
      },
      handlePermissionSuccess(){
        this.$refs.table.refresh();
      },
      handleDataSuccess(){
        this.$refs.table.refresh();
      },
      formatDate(row,column) {// 获取单元格数据
        let data = row[column.property];
        if(data == null) {
          return null;
        }
        let dt = new Date(data);
        return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
      },
	  async getSelectWl(){
		  var res = await this.$API.gjwl.wlWarehouse.listAll.get();
		  console.log(res)
		  if (res.code === 2000) {
		      this.wlWarehouseList = res.data;
		  }
	  },
    },
	beforeMount(){
		 this.getSelectWl();
	},
	mounted(){
		//0000
	},
	unmounted(){
		//
	},
  }
</script>
<style>
</style>
